//
//  MSTemplateTagsView.m
//  MSJD
//
//  Created by xiangbo on 2018/12/15.
//  Copyright © 2018 xiangbo. All rights reserved.
//

#import "MSTemplateTagsView.h"
#import "MSTagsView.h"

@interface MSTemplateTagsView()

@property (nonatomic,strong)id templateData;

@end

@implementation MSTemplateTagsView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
//        layout.itemSize = CGSizeMake(MS_SCREEN_WIDTH / 4, 90);
        self.collectionView.collectionViewLayout = layout;
        NSString *className = NSStringFromClass(MSTagsView.class);
        [self registetDetailView:className identifier:className];
        self.delegate = self;
        
    }
    return self;
}


- (NSString*)identifier:(id)data indexPath:(NSIndexPath *)indexPath{
    return NSStringFromClass(MSTagsView.class);
}

- (void)configData:(id)data indexPath:(NSIndexPath *)indexPath{
    self.templateData = data;
    if ([data isKindOfClass:MSFoodData.class]) {
        MSFoodData *modelData = (MSFoodData *)data;
        [self.dataArray removeAllObjects];
        for (MSFoodContentModel *foodContent in modelData.contents) {
            foodContent.kind = modelData.kind;
            [self.dataArray addObject:foodContent];
        }
    }
    [self.collectionView reloadData];
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return  CGSizeMake(MS_SCREEN_WIDTH  / 4 - 10, 90);
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
